/** 
* All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
* 
* PmBudgetLineService
* 项目预算明细
* 
* 修改纪录
* 2020-05-22 版本：1.0 shenyouyi 创建。
* @version 版本：1.0
* @author 作者：shenyouyi
* 创建日期：2020-05-22
*/
package com.topscomm.pm.service.impl;

import com.topscomm.basic.BasicEntity;
import com.topscomm.basic.exception.ServiceException;
import com.topscomm.pub.util.StringBufferProxy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.pm.service.IPmBudgetLineService;
import com.topscomm.pm.service.impl.auto.PmBudgetLineServiceAuto;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service(value = "pmBudgetLineService")
@Scope(value = "singleton")
public class PmBudgetLineService extends PmBudgetLineServiceAuto implements IPmBudgetLineService {

    /**
     * 重写beforeInsert方法，设置行号
     * @param entity
     * @throws ServiceException
     */
    @Override
    protected void beforeInsert(BasicEntity entity) throws ServiceException {
        super.beforeInsert(entity);
        String budgetapplyid = entity.getValue("budgetapplyid").toString();
        StringBufferProxy sql = new StringBufferProxy();
        sql.appendSingle("budgetapplyid = {0}", budgetapplyid);
        List<String> listFields = new ArrayList<>();
        listFields.add("max(lineno) as maxLineno");
        List<Map<String,Object>> queryResultList = this.queryMapFieldsByWhere(sql.toString(), listFields);
        Long maxLineno = 0L;
        if(queryResultList.size()>0&&queryResultList.get(0)!=null&&queryResultList.get(0).get("maxLineno")!=null){
            maxLineno = Long.valueOf(queryResultList.get(0).get("maxLineno").toString());
        }
        entity.setValue("lineno", maxLineno + 1);
    }
}
